import { NextRequest, NextResponse } from 'next/server';
import { db } from '@/lib/db';
import { orderActivities } from '@/lib/schema';
import { eq, desc } from 'drizzle-orm';

export async function GET(
  request: NextRequest,
  { params }: { params: Promise<{ id: string }> }
) {
  try {
    const resolvedParams = await params;
    const activities = await db
      .select()
      .from(orderActivities)
      .where(eq(orderActivities.orderId, parseInt(resolvedParams.id)))
      .orderBy(desc(orderActivities.createdAt));

    return NextResponse.json(activities);
  } catch (error) {
    console.error('获取订单活动记录失败:', error);
    return NextResponse.json(
      { error: '获取订单活动记录失败' },
      { status: 500 }
    );
  }
}